import Vue from "vue";
import toast from "./Toast";
//该toast为一个初始化Vue实例的option对象
console.log(toast);

// 通过Vue.extend创建一个继承Vue的子类，返回一个可以创建toast这个组件实例的构造函数
const Toast = Vue.extend(toast);

export default function install(Vue) {
  Vue.prototype.$Toast = (msg) => {
    const toastComp = new Toast({
      data() {
        return {
          msg,
        };
      },
    });
    // new 之后toastComp是组件实例
    console.log(toastComp, "new");
    //将该组件挂载
    toastComp.$mount();
    let dom = toastComp.$el;
    document.body.appendChild(dom);
  };
}
